package org.easyelf.pitaya.core.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @Title:
 * @Description:
 *              Restful API 访问路径:
 *              http://IP:port/{context-path}/swagger-ui.html
 *              eg:http://localhost:8080/pitaya/swagger-ui.html
 * @Package: org.easyelf.pitaya.core.config with IntelliJ IDEA
 * @User: rehn.gao
 * @Date: 2017/6/8
 * @Time: 上午11:18
 */
@Configuration //必须存在
@EnableSwagger2 //必须存在
@EnableWebMvc //必须存在
@ComponentScan(basePackages = {"org.easyelf.pitaya.admin.account.controller"}) //必须存在 扫描的API Controller package name 也可以直接扫描class (basePackageClasses)
public class Swagger2{
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("org.easyelf.pitaya.admin.account.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("Pitaya-Admin 后台管理系统")
                .description("©2017 Copyright. Powered By Rehn.gaO.")
                .contact(new Contact("Rehn.gaO", "", "rehn.gao@gmail.com"))
                .license("Apache License Version 2.0")
                .licenseUrl("https://github.com/springfox/springfox/blob/master/LICENSE")
                .termsOfServiceUrl("")
                .version("1.0")
                .build();
    }
}
